package jzqb.service.impl;

import haha.life.normal.FileUtil;
import haha.life.normal.FileuploadUtils;
import jzqb.bo.ZYBo;
import jzqb.common.Result;
import jzqb.dao.ZYDao;
import jzqb.service.ZYService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2020-09-22
 */
@Service
public class ZYServiceImpl implements ZYService {

    @Autowired
    ZYDao zyDao;

    @Value("${filePath.qbzyCoverPath}")
    private String qbzyCoverPath;

    @Override
    public Result getZyDetail(ZYBo zyBo) {
        ZYBo zyResult= zyDao.getZyDetail(zyBo);
        String cover = zyResult.getCover();
        if("".equals(cover) || cover == null){
            zyResult.setCoverByte(null);
        }else{
            String path = FileUtil.calculateAbstractPath(cover,qbzyCoverPath);
            if (!new File(path).exists() ) {
                zyResult.setCoverByte(null);
            } else {
                byte[] imageBinary = FileuploadUtils.getImageBinary(path);
                zyResult.setCoverByte(imageBinary);
            }
        }
        return Result.succ(zyResult);
    }
}